package com.lp.biz.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lp.biz.business.model.entity.Business;
import com.lp.biz.business.mapper.BusinessMapper;
import com.lp.biz.business.model.vo.BusinessList;
import com.lp.biz.business.service.BusinessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.lp.common.constant.CommonConstant.NEGATE;
import static com.lp.common.utils.Tools.copyPage;

/**
 * @program: backend
 * @description: Business 服务实现类
 * @author Ke.Song
 * @since 2024-09-23 20:56:30
 */
@Service
public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business> implements BusinessService {

    @Override
    public CommonResult getBusiness(PageParams query) {
        PageHelper.startPage(query.getPage(), query.getSize());
        List<Business> list = list(new QueryWrapper<Business>().lambda().eq(Business::getIsDeleted, NEGATE).orderByDesc(Business::getCreateAt));
        Page<BusinessList> businessLists = copyPage(new Page<>(), list);
        for (Business business : list) {
            businessLists.add(new BusinessList(business));
        }
        return CommonResult.restPage(businessLists);
    }
}
